
layui.use(['layer', 'form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;

    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(system.contextPath + "/admin/menu/append", function (res) {
            if(res.status){
                system.success("添加成功！");
                //传给上个页面，刷新table用
                admin.putTempData('formOk', true);
                //关掉对话框
                admin.closeThisDialog();
            }else{
                system.error("添加失败！" + res.msg);
            }
        }, function (res) {
            system.error("添加失败！" + res.msg);
        });

        //菜单值整理：：将菜单名配置给菜单请求uri，方便其接口获取和使用
        data.field.uri = data.field.uri.indexOf('?') == -1 ? data.field.uri + "?menuName=" + data.field.name : data.field.uri + "&menuName=" + data.field.name

        ajax.set(data.field);
        ajax.start();

        return false;
    });


    $('#menu-sel').click(function () {
        system.openDataSelector('/admin/menu/to/tree' ,'formContainer' ,'菜单选择');
    });
});